# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Maintainer: Ray Donnelly <mingw.android@gmail.com>

_realname=hlsl2glsl
pkgbase=mingw-w64-${_realname}-git
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
pkgver=r848.14dd189
pkgrel=1
epoch=1
pkgdesc="HLSL to GLSL shader language translator"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/aras-p/hlsl2glslfork'
license=('MIT')
makedepends=("git" "${MINGW_PACKAGE_PREFIX}-cmake" "${MINGW_PACKAGE_PREFIX}-cc")
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
options=('!strip' '!emptydirs')
_commit="14dd189562ea32979ff9b1ac9b047c744393f7bf"
source=("${_realname}"::"git+https://github.com/aras-p/hlsl2glslfork.git#commit=${_commit}"
        0001-CMakeLists.txt-Fixes-and-improvements.patch
        0002-Fix-pool_allocator-compile-guards.patch
        0003-hlsl2glsltest-Change-_MSC_VER-to-_WIN32.patch
        0004-CMake-Handle-installation.patch)
sha256sums=('SKIP'
            'd527524ebe9d381f8970844a31d50f0b4c3844b805408a2aaf4e3c63a0812d12'
            '352784c15bd464df885947fa36fec3ba6cd984e3bbf90be2377764492ef4f709'
            '121c1664931f0ea1d3006c5c0b8415014d1ff597bd5d3ec3b272c6bcf60f4192'
            'a28b97c6782706eeb2cae14e23be86f5e59c25cf5399f3c37f249b5723d020a1')

pkgver() {
  cd "${srcdir}"/${_realname}
  printf "r%s.%s" "$(git rev-list --count "${_commit}")" "$(git rev-parse --short "${_commit}")"
}

prepare() {
  cd "${srcdir}"/${_realname}
  git apply "${srcdir}"/0001-CMakeLists.txt-Fixes-and-improvements.patch
  git apply "${srcdir}"/0002-Fix-pool_allocator-compile-guards.patch
  git apply "${srcdir}"/0003-hlsl2glsltest-Change-_MSC_VER-to-_WIN32.patch
  git apply "${srcdir}"/0004-CMake-Handle-installation.patch
}

build() {
  mkdir -p build-${MSYSTEM} && cd build-${MSYSTEM}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX" \
    ${MINGW_PREFIX}/bin/cmake \
      -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
      -G"MSYS Makefiles" \
      "${srcdir}"/${_realname}

  make
}

package() {
  cd build-${MSYSTEM}
  make install DESTDIR="${pkgdir}"
}
